export default {
  namespaced: true,
  state: {
    test: '测试',
    cart: uni.getStorageSync('cart') || []
  },
  mutations: {
    addToCart(state, goodsObj) {
      let obj = state.cart.find(item => item.goods_id === goodsObj.goods_id)
      if (!obj) {
        state.cart.push(goodsObj)
      } else {
        obj.goods_count += 1
      }
      console.log(state.cart)
      uni.setStorageSync('cart', state.cart)
    }
  },
  actions: {},
  getters: {
    total(state) {
      return state.cart.reduce((sum, item) => {
        return sum += item.goods_count
      }, 0)
    }
  }
}
